package com.example.spring_boo_test1.Utils;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class DirectoryScanner {

    public static List<String> getAllFileNames(String directoryPath) {
        List<String> fileNames = new ArrayList<>();
        File directory = new File(directoryPath);
        getAllFileNames(directory, fileNames);
        return fileNames;
    }

    private static void getAllFileNames(File directory, List<String> fileNames) {
        File[] files = directory.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isFile()) {
                    fileNames.add(file.getName());
                } else if (file.isDirectory()) {
                    getAllFileNames(file, fileNames);
                }
            }
        }
    }

    public static void main(String[] args) {
        String directoryPath = "C:\\MyFiles\\downloads";
        List<String> fileNames = getAllFileNames(directoryPath);
        for (String fileName : fileNames) {
            System.out.println(fileName);
        }
    }
}
